#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include<QNetworkDatagram>
#define senderAddress "43.140.252.84"
#define senderPort 8085

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    socket=new QUdpSocket();
    connect(socket,&QUdpSocket::readyRead,this,&MainWindow::processRequest);



}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::processRequest()
{
    QNetworkDatagram responseDatagram=socket->receiveDatagram();
    QString response=responseDatagram.data();
    response="server said"+response;
    ui->listWidget->addItem(response);


}

void MainWindow::on_pushButton_clicked()
{
    QString requset=ui->lineEdit->text();
    QNetworkDatagram requestDatagram(requset.toUtf8(), QHostAddress(senderAddress), senderPort);
    socket->writeDatagram(requestDatagram);
    ui->lineEdit->setText("");

}
